const http = require('http')

// 1. 引入 url 模块
const url = require('url')

const server = http.createServer((request, response) => {
    response.setHeader('content-type', 'text/html;charset=utf-8')

    // 2.解析request.url
    console.log(request.url) // /seach?username=1&password=1

    let res = url.parse(request.url)

    let pathname = res.pathname

    // URL 路径
    console.log(pathname) ///seach

    /**
     *   url.parse(request.url,true)  第二个参数传  true 则会把 query 转为对象的形式
     *
     * */

    // 查询字符串
    let res1 = url.parse(request.url,true)
    console.log(res1)
    console.log(res1.query.password)

    // 3. 访问路径 http://127.0.0.1:9090/seach?username=1&password=1


    response.end('hello')

})
server.listen(9090, () => {
    console.log('服务启动')
})